package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.aid.AidTransport;
import com.ruoyi.system.service.aid.IAidTransportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物流运输Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/aid/transport")
public class AidTransportController extends BaseController {
    @Autowired
    private IAidTransportService transportService;

    /**
     * 查询物流运输列表
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:list')")
    @GetMapping("/list")
    public TableDataInfo list(AidTransport transport) {
        startPage();
        List<AidTransport> list = transportService.selectTransportList(transport);
        return getDataTable(list);
    }

    /**
     * 导出物流运输列表
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:export')")
    @Log(title = "物流运输", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AidTransport transport) {
        List<AidTransport> list = transportService.selectTransportList(transport);
        ExcelUtil<AidTransport> util = new ExcelUtil<AidTransport>(AidTransport.class);
        return util.exportExcel(list, "物流运输数据");
    }

    /**
     * 获取物流运输详细信息
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:query')")
    @GetMapping(value = "/{transportId}")
    public AjaxResult getInfo(@PathVariable("transportId") Long transportId) {
        return success(transportService.selectTransportById(transportId));
    }

    /**
     * 新增物流运输
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:add')")
    @Log(title = "物流运输", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AidTransport transport) {
        return toAjax(transportService.insertTransport(transport));
    }

    /**
     * 修改物流运输
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:edit')")
    @Log(title = "物流运输", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AidTransport transport) {
        return toAjax(transportService.updateTransport(transport));
    }

    /**
     * 删除物流运输
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:remove')")
    @Log(title = "物流运输", businessType = BusinessType.DELETE)
    @DeleteMapping("/{transportIds}")
    public AjaxResult remove(@PathVariable Long[] transportIds) {
        return toAjax(transportService.deleteTransportByIds(transportIds));
    }

    /**
     * 根据承运商ID查询运输列表
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:query')")
    @GetMapping("/carrier/{carrierId}")
    public AjaxResult getByCarrierId(@PathVariable("carrierId") Long carrierId) {
        return success(transportService.selectTransportByCarrierId(carrierId));
    }

    /**
     * 根据分配ID查询运输列表
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:query')")
    @GetMapping("/allocation/{allocationId}")
    public AjaxResult getByAllocationId(@PathVariable("allocationId") Long allocationId) {
        return success(transportService.selectTransportByAllocationId(allocationId));
    }

    /**
     * 根据状态查询运输列表
     */
    @PreAuthorize("@ss.hasPermi('aid:transport:query')")
    @GetMapping("/status/{status}")
    public AjaxResult getByStatus(@PathVariable("status") String status) {
        return success(transportService.selectTransportByStatus(status));
    }
} 